#!/usr/bin/env bash

# Issue warnings about the number of Slurm jobs approaching MaxJobCount.
# Homepage: https://github.com/OleHolmNielsen/Slurm_tools/

# This script might be run regularly from crontab , for example:
# 5 * * * * /usr/local/bin/warn_maxjobs

# Set the percentage of MaxJobCount above which we print a warning.
export maxjobpercent=80

export NUMJOBS=`squeue -hO JobID | wc -l`
export MAXJOBCOUNT=`scontrol show config | grep MaxJobCount | awk '{print $3}'`
# Check if NUMJOBS exceeds some percentage of the maximum:
if (( NUMJOBS > maxjobpercent*MAXJOBCOUNT/100 ))
then
	echo "*** WARNING: *** The number of jobs is getting close to the MaxJobCount limit in slurm.conf."
	echo "Job summary: $NUMJOBS jobs total (max=$MAXJOBCOUNT) in all partitions."
fi

